package Morning.Interator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Interator03 {
    public static void main(String[] args) {

        //迭代器,对象调用Iterator();
        // hasNext判断当前索0引是否要元素,boolean
        // next取出当前元素+迭代器索引后移一个位子,
        //迭代器里的remove删除的是所有相同的元素
        //增强for底层也是迭代器完成的但是它只能用于遍历不能用于,添加/删除/索引
        // iter
        //  集合名.for

        Collection<Student> res = new ArrayList<>();

        res.add(new Student("张三", "男", 20));
        res.add(new Student("张三封", "男", 30));
        res.add(new Student("翠花", "女", 20));
        res.add(new Student("王老五", "男", 19));
        res.add(new Student("李四", "男", 21));


        Iterator<Student> num = res.iterator();

        while (num.hasNext()){
           Student res1 = num.next();
            if(res1.getName().length()>2){

                num.remove();

            }

        }
        for (Student re : res) {
            
        }

    }
}
